package com.hexb.smh.entity.param.commission;

import com.hexb.smh.entity.Commission;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import java.math.BigDecimal;

import static com.hexb.smh.utils.SmhConstant.AMOUNT_PATTERN;
import static com.hexb.smh.utils.SmhConstant.RATE_PATTERN;

/**
 * @author : hexb
 */
@Data
public class CommissionParam {

    @ApiModelProperty(value = "折扣最低(不包含)", example = "9.5")
    @NotNull
    @Pattern(regexp = RATE_PATTERN)
    private String minDiscount;

    @ApiModelProperty(value = "折扣最高(包含)", example = "10")
    @Pattern(regexp = RATE_PATTERN)
    @NotNull
    private String maxDiscount;

    @ApiModelProperty(value = "成交金额最低", example = "100")
    @Pattern(regexp = AMOUNT_PATTERN)
    @NotNull
    private String minAmount;

    @ApiModelProperty(value = "成交金额最高", example = "200")
    @Pattern(regexp = AMOUNT_PATTERN)
    @NotNull
    private String maxAmount;

    @ApiModelProperty(value = "提成金额", example = "7")
    @Pattern(regexp = AMOUNT_PATTERN)
    @NotNull
    private String amount;

    public Commission toCommission() {
        Commission c = new Commission();
        c.setMinAmount(new BigDecimal(minAmount));
        c.setMaxAmount(new BigDecimal(maxAmount));
        c.setMaxDiscount(new BigDecimal(maxDiscount));
        c.setMinDiscount(new BigDecimal(minDiscount));
        c.setAmount(new BigDecimal(amount));

        c.setAmountKey(c.createAmountKey());
        c.setDiscountKey(c.createDiscountKey());
        return c;
    }

    public static class CommissionInsertParam extends CommissionParam {


    }

    @Data
    public static class CommissionUpdateParam {

        @ApiModelProperty("提成金额")
        @Pattern(regexp = AMOUNT_PATTERN)
        @NotNull
        private String amount;

        public Commission toCommission(Integer id) {
            Commission commission = new Commission();
            commission.setId(id);
            return commission;
        }
    }
}
